<template>
  <div class="media-list-control">
    <div
      class="col-md-6"
      v-for="(item, index) in data"
      :key="index"
      :style="
        screenWidth > 767
          ? {
              padding: index % 2 === 0 ? '0 .9375rem 0 0' : '0 0 0 .9375rem',
            }
          : {}
      "
      :class="screenWidth > 767 ? 'large' : 'small'"
    >
      <div class="es-media" style="margin-bottom: 1.25rem">
        <div class="es-img">
          <img
            :src="item.img"
            class="es-media-img"
            alt="..."
            style="object-fit: cover"
          />
        </div>
        <div class="es-media-body">
          <h5 class="mt-0">{{ item.title }}</h5>
          <p>
            {{ item.desc }}
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "MediaListControl",
  props: {
    data: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      screenWidth: 0,
    };
  },
  created() {
    this.screenWidth = screen.width;
    window.addEventListener("resize", this.reloadPage);
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.reloadPage);
  },
  methods: {
    reloadPage() {
      this.screenWidth = screen.width;
    },
  },
};
</script>

<style lang="scss">
.media-list-control {
  padding: 0 0 2rem 0;
  overflow: hidden;
  .large {
    padding: 0.3125rem 0;
    float: left;
    width: 50%;
  }
  .small {
    padding: 0;
    margin: 0.625rem 0;
  }
  .es-img {
    display: block;
    .es-media-img {
      width: 2rem;
      height: 2rem;
      margin-right: 0.625rem;
      background-color: var(--light);
      border-radius: 0.25rem;
      padding: 0.3125rem;
    }
  }
  .es-media-body {
    p {
      font-size: 1rem;
    }
  }
}
</style>
